<div class="col-lg-12">
    <div>
        <div class="card col-md-12">
            <div class="card-header">
                <h4 style="font-size: 20px"><a class='mdi mdi-arrow-left-thick left'
                                               style='cursor: pointer;padding: 0 10px 0 0' title='返回商品列表'
                                               onclick='product_list_page()'></a>商品详情</h4>
            </div>
            <div class="row">
                <div class="card-body">
                    <div class="col-md-6 text-center">
                        <div class="form-group">
                            <div><img id="img-display" src="" alt="" style="width: 220px;height: 220px"></div>
                        </div>
                    </div>
                    <div class="col-md-6 text-center">
                        <div class="form-group" style="padding: 0 10px 5px 10px">
                            <label style="font-size: 20px">商品标题</label>
                            <div id="title-display"></div>
                        </div>
                        <div class="form-group" style="padding: 5px 10px">
                            <label style="font-size: 20px">商品价格</label>
                            <div id="price-display"></div>
                        </div>
                        <div class="form-group" style="padding: 5px 10px 0 10px">
                            <label style="font-size: 20px">商品评分</label>
                            <div id="star-display"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group text-center">
                <button class="btn btn-primary"
                        onclick='product_update_page(product_id);'>修改商品
                </button>
                <button class="btn btn-primary"
                        onclick='product_vip_page(product_id);'>开通VIP
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    var response = product_seller_get(localStorage.getItem("token"), product_id);
    if (response === null) {
        alert("无对应商品信息，请检查操作是否正确");
        $("main").load("element/product-list.html");
    }
    document.getElementById("img-display").src = response.filePath;
    document.getElementById("title-display").innerHTML = response.title;
    document.getElementById("price-display").innerHTML = "￥" + response.price.toFixed(2);
    document.getElementById("star-display").innerHTML = (response.star !== null ? response.star.toFixed(2) : "暂无评分");
    $("#update_product_button").on("click", function () {
        var formData = new FormData();
        formData.append("productId", product_id);
        var file = document.getElementById("file-input").files[0];
        if (file !== undefined) {
            formData.append("picture", file);
        }
        var price = document.getElementById("price-input").value;
        formData.append("price", price);
        var title = document.getElementById("title-input").value;
        formData.append("title", title);
        var token = localStorage.getItem("token");
        formData.append("token", token);
        if (product_seller_update(formData)) {
            product_list_page();
        }
    })
</script>